package com.aqa.ms.alo;

/**
 * 重复项删除
 */
public class DuplicateDelete {

    public static void main(String[] args) {
        String a = "abbcdeffg";
        System.out.println("duplicateDel(a) = " + duplicateDel(a));
    }

    private static String duplicateDel(String a) {
        char[] rs = new char[a.length()];
        char[] chars = a.toCharArray();
        for (int i = 0, j = 0; i < chars.length - 1; i++, j++) {
            if (chars[i] == chars[i + 1]) {
                continue;
            }
            rs[j] = chars[i];
            if (i + 1 == chars.length - 1) {
                rs[++j] = chars[i + 1];
            }
        }
        return new String(rs);
    }


}
